package org.duiduo.common.feign.config;

import cn.hutool.core.util.StrUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.MDC;

/**
 * feign调用请求拦截器
 *
 * @author liangze
 * @date 2024/10/12 10:56
 */
public class FeignReqInterceptor implements RequestInterceptor {

    public static final String HEADER_TRACE_ID = "X-Trace-ID";
    public static final String TRACE_ID = "trace_id";

    @Override
    public void apply(RequestTemplate template) {
        String traceId = MDC.get(TRACE_ID);
        if (StrUtil.isNotEmpty(traceId)) {
            template.header(HEADER_TRACE_ID, traceId);
        }
    }
}